<template>
  <div class="bg">
    <!-- <div>
      考试宣读规则
    </div> -->
    <audio src="../assets/欢迎宣读规则.mp3" autoplay></audio>
  </div>
</template>

<script>
export default {
  data() {
    return {
      showTime: true,
      day: '',
      hr: '',
      min: '',
      sec: '',
      time: 0,
    };
  },
  mounted() {
    this.endTime = Date.parse(new Date('2021-07-01 17:32:00 ')); // 截止时间为固定值
    this.endTime = Date.parse(new Date()) + 21000; // 截止时间为5分钟（当前时间的五分钟后,1min为60000ms,5min故为300000ms,当前时间的时间戳加上毫秒数）
    this.countdownPay();
  },
  methods: {
    countdownPay() {
      const end = this.endTime;
      const now = Date.parse(new Date());
      const msec = end - now;
      this.time = msec;
      if (msec < 0) return;
      let day = parseInt(msec / 1000 / 60 / 60 / 24);
      let hr = parseInt((msec / 1000 / 60 / 60) % 24);
      let min = parseInt((msec / 1000 / 60) % 60);
      let sec = parseInt((msec / 1000) % 60);
      this.day = day;
      this.hr = hr > 9 ? hr : '0' + hr;
      this.min = min > 9 ? min : '0' + min;
      this.sec = sec > 9 ? sec : '0' + sec;
      const that = this;

      if (min >= 0 && sec >= 0) {
        if (min == 0 && sec == 0) {
          that.showTime = false;
          return;
        }
        setTimeout(function () {
          that.countdownPay();
        }, 1000);
      }
    },
  },
  watch: {
    //监听时间的变化
    time(val) {
      // console.log(val);
      if (val == 0) {
        this.$router.push('inTheExam');
      }
    },
  },
};
</script>

<style scoped>
.bg {
  background-image: url('../assets/微信图片_20230423224512.png');
  background-repeat: no-repeat;
  height: 100%;
}
</style>